package com.knight.hadoop.day08.flow;

import java.util.HashMap;
import java.util.Map;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.lib.HashPartitioner;
import org.apache.hadoop.mapreduce.Partitioner;
import org.junit.Test;

/**
 * 改写数据分发（分组）组件Partitioner
 * @author 
 *
 */
public class ProvincePartitioner extends Partitioner<Text, FlowModel>{
	
	private static Map<String,Integer> provinceDict= new HashMap<>();
	static{
		provinceDict.put("136", 0);
		provinceDict.put("137", 1);
		provinceDict.put("138", 2);
		provinceDict.put("139", 3);
	}
	
	
	@Override
	public int getPartition(Text key, FlowModel value, int numPartitions) {
		
		Integer provinceId = provinceDict.get(key.toString().substring(0, 3));
		
		return provinceId==null? 4 : provinceId;
	}
}
